package com.indexingsystem.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.ResCategoryRelationsVo;
import com.indexingsystem.boss.Vo.VideosReqVo;
import com.indexingsystem.boss.Vo.VideosTableVo;
import com.indexingsystem.boss.Vo.VideosVo;
import com.indexingsystem.boss.admin.mapper.AuditLogsMapper;
import com.indexingsystem.boss.admin.mapper.DhResourceauditlogsMapper;
import com.indexingsystem.boss.admin.mapper.ResCategoryRelationsMapper;
import com.indexingsystem.boss.admin.mapper.ResourceRelationsMapper;
import com.indexingsystem.boss.admin.mapper.ResourceTypeMapper;
import com.indexingsystem.boss.admin.mapper.ResourcesMapper;
import com.indexingsystem.boss.admin.mapper.SpecialResourceDatasMapper;
import com.indexingsystem.boss.admin.mapper.VideosMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.AuditLogs;
import com.indexingsystem.boss.entity.DhResourceauditlogs;
import com.indexingsystem.boss.entity.DhTodayStorageInfos;
import com.indexingsystem.boss.entity.ResCategoryRelations;
import com.indexingsystem.boss.entity.ResourceCategors;
import com.indexingsystem.boss.entity.ResourceRelations;
import com.indexingsystem.boss.entity.ResourceType;
import com.indexingsystem.boss.entity.ResourceUpdateRecord;
import com.indexingsystem.boss.entity.Resources;
import com.indexingsystem.boss.entity.SpecialResourceDatas;
import com.indexingsystem.boss.entity.Videos;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.boss.utils.DateUtil;
import com.indexingsystem.boss.utils.InstitutionLoadUtils;
import com.indexingsystem.boss.utils.StringUtil;
import com.indexingsystem.db.mongoDB.impl.ResourceCategorsResListMongo;
import com.indexingsystem.db.mongoDB.impl.VideosMongo;
import com.indexingsystem.db.mongoDB.po.ResourceCategorsResPo;
import com.indexingsystem.db.mongoDB.po.VideosResourceMongoVo;
import com.indexingsystem.system.service.IResourceCategorsService;
import com.indexingsystem.system.service.IResourceUpdateRecordService;
import com.indexingsystem.system.service.IVideosService;
import com.indexingsystem.system.service.IdhTodayStorageInfosService;

@Service
public class VideosServiceImpl implements IVideosService {

	@Resource
	private VideosMapper					videosMapper;

	@Resource
	private ResourcesMapper					resourcesMapper;

	@Resource
	private ResCategoryRelationsMapper		resCategoryRelationsMapper;

	@Resource
	private SpecialResourceDatasMapper		specialResourceDatasMapper;

	@Resource
	private AuditLogsMapper					auditLogsMapper;

	@Resource
	private IdhTodayStorageInfosService		todayStorageInfosDao;

	@Resource
	private DhResourceauditlogsMapper		dhResourceauditlogsMapper;

	@Resource
	private ResourceRelationsMapper			resourceRelationsMapper;

	@Resource
	private ResourceTypeMapper				resourceTypeMapper;

	@Resource
	private IResourceUpdateRecordService	iResourceUpdateRecordService;

	@Resource
	private IResourceCategorsService		iResourceCategorsService;

	@Override
	public int deleteByPrimaryKey(String resId) {
		return videosMapper.deleteByPrimaryKey( resId );
	}

	@Override
	public int insertSelective(Videos record) {
		return videosMapper.insertSelective( record );
	}

	@Override
	public PagedResult<VideosTableVo> selectVideosList(VideosVo videosVo) {
		Integer pageNo = videosVo.getPageNumber() == null ? 1 : videosVo.getPageNumber();
		Integer pageSize = videosVo.getPageSize() == null ? 10 : videosVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		String format = "Videos";
		List<VideosTableVo> videosTableVoList = VideosMongo.findVideosByPage( videosVo, format, InstitutionLoadUtils.getString( "institutionId" ) );
		if (null != videosTableVoList && videosTableVoList.size() > 0) {
			return BeanUtils.toPagedResult( videosTableVoList );
		} else {
			videosTableVoList = videosMapper.selectVideosList( videosVo );
			return BeanUtils.toPagedResult( videosTableVoList );
		}

	}

	@Override
	public Integer getVideosListCount(VideosVo record) {
		Integer maxCount = 0;
		String format = "Videos";
		maxCount = VideosMongo.findVideosMaxCount( record, format, InstitutionLoadUtils.getString( "institutionId" ) );
		if (maxCount == 0) {
			maxCount = videosMapper.getVideosListCount( record );
		}
		return maxCount;
	}

	@Override
	public PagedResult<VideosTableVo> selectPictureList(VideosVo videosVo) {

		Integer pageNo = videosVo.getPageNumber() == null ? 1 : videosVo.getPageNumber();
		Integer pageSize = videosVo.getPageSize() == null ? 10 : videosVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		String format = "Pictures";
		List<VideosTableVo> videosTableVoList = VideosMongo.findVideosByPage( videosVo, format, InstitutionLoadUtils.getString( "institutionId" ) );
		if (null != videosTableVoList && videosTableVoList.size() > 0) {
			return BeanUtils.toPagedResult( videosTableVoList );
		} else {
			videosTableVoList = videosMapper.selectPictureList( videosVo );
			return BeanUtils.toPagedResult( videosTableVoList );
		}

	}

	@Override
	public Integer getPictureListCount(VideosVo record) {
		Integer maxCount = 0;
		String format = "Pictures";
		maxCount = VideosMongo.findVideosMaxCount( record, format, InstitutionLoadUtils.getString( "institutionId" ) );
		if (maxCount == 0) {
			maxCount = videosMapper.getVideosListCount( record );
		}
		return maxCount;
	}

	@Override
	public Videos selectByPrimaryKey(String resId) {
		return videosMapper.selectByPrimaryKey( resId );
	}

	@Override
	public int updateByPrimaryKeySelective(Videos record) {
		return videosMapper.updateByPrimaryKeySelective( record );
	}

	@Override
	public List<VideosVo> searchVideosList(VideosVo record) {
		return videosMapper.searchVideosList( record );
	}

	@Override
	public int addVideosInfo(VideosReqVo videosReqVo, AuditLogs auditLogs, DhTodayStorageInfos dhTodayStorageInfos) throws Exception {
		int result = 0;
		if (null != videosReqVo) {
			VideosResourceMongoVo videosResourceMongoVo = new VideosResourceMongoVo();
			Resources resources = videosReqVo.getResources();
			String resTable = "";
			if (null != resources) {
				resourcesMapper.insertSelective( resources );

				videosResourceMongoVo.setResId( resources.getResId() );

				ResourceType resourceType = resourceTypeMapper.selectByPrimaryKey( resources.getResTypeId() );
				resTable = resourceType.getResTable();

				videosResourceMongoVo.setResTypeId( resources.getResTypeId() );
				videosResourceMongoVo.setResTable( resTable );
				videosResourceMongoVo.setResources( resources );
			}
			Videos videos = videosReqVo.getVideos();
			if (null != videos) {
				result = videosMapper.insertSelective( videos );
				videosResourceMongoVo.setVideos( videos );
			}
			ResCategoryRelations resCategoryRelation = null;
			List<ResCategoryRelations> resultResCategoryRelationsList = null;
			List<ResCategoryRelationsVo> resCategoryRelationsVoList = videosReqVo.getResCategoryRelationsList();
			if (null != resCategoryRelationsVoList && resCategoryRelationsVoList.size() > 0) {
				resultResCategoryRelationsList = new ArrayList<ResCategoryRelations>();
				for (ResCategoryRelationsVo resCategoryRela : resCategoryRelationsVoList) {
					resCategoryRelation = new ResCategoryRelations();
					resCategoryRelation.setResCategoryRelationId( resCategoryRela.getResCategoryRelationId() );
					resCategoryRelation.setResCategoryId( resCategoryRela.getResCategoryId() );
					resCategoryRelation.setResId( resCategoryRela.getResId() );
					if (!resultResCategoryRelationsList.contains( resCategoryRelation )) {
						resultResCategoryRelationsList.add( resCategoryRelation );
					}
				}
			}
			if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
				resCategoryRelationsMapper.insertResCategoryRelationsBatch( resultResCategoryRelationsList );
				videosResourceMongoVo.setResCategoryRelationsList( resultResCategoryRelationsList );
				for (ResCategoryRelationsVo resCategoryRela : resCategoryRelationsVoList) {
					// 登记资源分类资源变更表
					// 记录接触关系的资源
					ResourceUpdateRecord resourceUpdateRecord = new ResourceUpdateRecord();
					resourceUpdateRecord.setResourceUpdateRecordId( StringUtil.createSystemDataPrimaryKey() );
					resourceUpdateRecord.setResId( resCategoryRela.getResId() );
					ResourceType resType = resourceTypeMapper.selectResourceTypeResTableExits( "Videos" );
					resourceUpdateRecord.setResTable( resType.getResTable() );
					resourceUpdateRecord.setResTypeId( resType.getResTypeId() );
					resourceUpdateRecord.setSuperCategoryId( resCategoryRela.getParentId() );
					resourceUpdateRecord.setResourceCategoryId( resCategoryRela.getResCategoryId() );
					resourceUpdateRecord.setOperatedate( DateUtil.getCurDate_YYYY_MM_DD() );
					resourceUpdateRecord.setState( "1" );
					iResourceUpdateRecordService.insert( resourceUpdateRecord );
				}

			}
			List<SpecialResourceDatas> specialResourceDatasList = videosReqVo.getSpecialResourceDatasList();
			if (null != specialResourceDatasList && specialResourceDatasList.size() > 0) {
				specialResourceDatasMapper.batchAddSpecialResourceDatas( specialResourceDatasList );
				videosResourceMongoVo.setDhSpecialResourceDatasList( specialResourceDatasList );
			}

			// 报刊缓存mongo
			List<ResourceCategorsResPo> resourceCategorsResPoList = null;
			if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
				resourceCategorsResPoList = new ArrayList<ResourceCategorsResPo>();
				for (ResCategoryRelations resCategoryRelations : resultResCategoryRelationsList) {
					ResourceCategorsResPo resourceCategorsResPo = new ResourceCategorsResPo();
					resourceCategorsResPo.setThumbnail( videos.getFrontCover() );
					resourceCategorsResPo.setResType( 2 );
					String publishDate = resources.getPublishDate();

					resourceCategorsResPo.setDatePx( DateUtil.parseFormatToPublishDate( publishDate ) );
					resourceCategorsResPo.setPublishDate( publishDate );

					resourceCategorsResPo.setResId( resCategoryRelations.getResId() );
					resourceCategorsResPo.setResName( resources.getResName() );
					resourceCategorsResPo.setPublishDate( resources.getPublishDate() );
					resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
					resourceCategorsResPo.setResCategoryId( resCategoryRelations.getResCategoryId() );
					resourceCategorsResPo.setStatus( resources.getStatus() );

					// 通过资源分类id获取资源分类名称
					ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
					resourceCategorsResPo.setResCategoryName( resourceCategors.getResName() );
					resourceCategorsResPo.setResTable( resTable );

					if (!resourceCategorsResPoList.contains( resourceCategorsResPo )) {
						resourceCategorsResPoList.add( resourceCategorsResPo );
					}
					ResourceCategorsResListMongo.addResourceCategorsResList( resourceCategorsResPoList,
							InstitutionLoadUtils.getString( "institutionId" ) );
				}
			}

			// 新增流水号
			todayStorageInfosDao.insert( dhTodayStorageInfos );
			videosResourceMongoVo.setTodayStorageInfos( dhTodayStorageInfos );

			// 判斷資源ID是否存在
			DhResourceauditlogs resAuditLogsList = dhResourceauditlogsMapper.getResAuditlogsByResId( resources.getResId() );
			if (null == resAuditLogsList) {
				DhResourceauditlogs resourceauditlogs = new DhResourceauditlogs();
				resourceauditlogs.setCreatedate( DateUtil.parseFormatToDate( DateUtil.getCurTotalDate() ) );
				resourceauditlogs.setDescription( "音视频资源类型批量入库" );
				resourceauditlogs.setHandler( resources.getCreateUserId() == null ? "admin" : resources.getCreateUserId() );
				resourceauditlogs.setStatus( 1 );
				resourceauditlogs.setResid( resources.getResId() );
				resourceauditlogs.setId( StringUtil.createSystemDataPrimaryKey() );
				dhResourceauditlogsMapper.insertSelective( resourceauditlogs );
				videosResourceMongoVo.setResourceauditlogs( resourceauditlogs );
			} else {
				videosResourceMongoVo.setResourceauditlogs( resAuditLogsList );
			}

			auditLogsMapper.insertSelective( auditLogs );
			videosResourceMongoVo.setAuditLogs( auditLogs );

			// 资源关系
			List<ResourceRelations> queryResRelationsList = this.resourceRelationsMapper.getResourceRelationsListByResId( resources.getResId() );
			videosResourceMongoVo.setDhResourceRelationsList( queryResRelationsList );

			VideosMongo.addVideos( videosResourceMongoVo, InstitutionLoadUtils.getString( "institutionId" ) );

		}
		return result;
	}

	/**
	 * 视频管理及图片管理修改操作.
	 */
	@Override
	public int updateVideosInfo(VideosReqVo videosReqVo) throws Exception {
		int result = 0;
		String resTable = "";
		if (null != videosReqVo) {
			VideosResourceMongoVo videosResourceMongoVo = new VideosResourceMongoVo();
			Resources resources = videosReqVo.getResources();
			if (null != resources) {
				resourcesMapper.updateByPrimaryKeySelective( resources );

				ResourceType resourceType = resourceTypeMapper.selectByPrimaryKey( resources.getResTypeId() );
				resTable = resourceType.getResTable();

				Resources resourcesObj = resourcesMapper.selectByPrimaryKey( resources.getResId() );
				videosResourceMongoVo.setResId( resourcesObj.getResId() );
				videosResourceMongoVo.setResTypeId( resourcesObj.getResTypeId() );
				videosResourceMongoVo.setResTable( resTable );
				videosResourceMongoVo.setResources( resourcesObj );

			}
			Videos videos = videosReqVo.getVideos();
			if (null != videos) {
				result = videosMapper.updateByPrimaryKeySelective( videos );

				Videos videosObj = videosMapper.selectByPrimaryKey( videos.getResId() );
				videosResourceMongoVo.setVideos( videosObj );
			}
			ResCategoryRelations resCategoryRelation = null;
			List<String> resIdList = null;
			List<String> resCategoryIdList = null;
			List<ResCategoryRelations> resultResCategoryRelationsList = null;
			List<ResCategoryRelationsVo> resCategoryRelationsVoList = videosReqVo.getResCategoryRelationsList();
			if (null != resCategoryRelationsVoList && resCategoryRelationsVoList.size() > 0) {
				resIdList = new ArrayList<String>();
				resCategoryIdList = new ArrayList<String>();
				resultResCategoryRelationsList = new ArrayList<ResCategoryRelations>();
				for (ResCategoryRelationsVo resCategoryRela : resCategoryRelationsVoList) {
					resCategoryRelation = new ResCategoryRelations();
					resCategoryRelation.setResCategoryRelationId( StringUtil.createSystemDataPrimaryKey() );
					resCategoryRelation.setResCategoryId( resCategoryRela.getResCategoryId() );
					resCategoryRelation.setResId( resCategoryRela.getResId() );
					resCategoryIdList.add( resCategoryRela.getResCategoryId() );
					resIdList.add( resCategoryRela.getResId() );

					if (!resultResCategoryRelationsList.contains( resCategoryRelation )) {
						resultResCategoryRelationsList.add( resCategoryRelation );
					}
				}
			}

			List<SpecialResourceDatas> specialResourceDatasList = videosReqVo.getSpecialResourceDatasList();
			if (null != specialResourceDatasList && specialResourceDatasList.size() > 0) {
				if (null != resIdList && resIdList.size() > 0) {
					// 终端先删后加
					specialResourceDatasMapper.deleteSpecialResourceDatasByIdBatch( resIdList );
				}
				specialResourceDatasMapper.batchAddSpecialResourceDatas( specialResourceDatasList );
			}
			videosResourceMongoVo.setDhSpecialResourceDatasList( specialResourceDatasList );

			if (null != resIdList && resIdList.size() > 0) {
				// 先删后加
				resCategoryRelationsMapper.deleteResBatchCategoryRelationsByResId( resIdList );
				if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
					// 后加
					resCategoryRelationsMapper.insertResCategoryRelationsBatch( resultResCategoryRelationsList );
					videosResourceMongoVo.setResCategoryRelationsList( resultResCategoryRelationsList );

					// 先通过resId清理所有分类列表
					List<String> delResIdList = new ArrayList<String>();
					delResIdList.add( resources.getResId() );
					ResourceCategorsResListMongo.deleteResCategoryRelationsByResId( delResIdList, InstitutionLoadUtils.getString( "institutionId" ) );

					// 报刊缓存mongo
					List<ResourceCategorsResPo> resourceCategorsResPoList = null;
					if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
						resourceCategorsResPoList = new ArrayList<ResourceCategorsResPo>();
						for (ResCategoryRelations resCategoryRelations : resultResCategoryRelationsList) {
							ResourceCategorsResPo resourceCategorsResPo = new ResourceCategorsResPo();
							resourceCategorsResPo.setThumbnail( videos.getFrontCover() );
							resourceCategorsResPo.setResType( 2 );
							String publishDate = resources.getPublishDate();

							resourceCategorsResPo.setDatePx( DateUtil.parseFormatToPublishDate( publishDate ) );
							resourceCategorsResPo.setPublishDate( publishDate );

							resourceCategorsResPo.setResId( resCategoryRelations.getResId() );
							resourceCategorsResPo.setResName( resources.getResName() );
							resourceCategorsResPo.setPublishDate( resources.getPublishDate() );
							resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
							resourceCategorsResPo.setResCategoryId( resCategoryRelations.getResCategoryId() );
							resourceCategorsResPo.setStatus( resources.getStatus() );

							// 通过资源分类id获取资源分类名称
							ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
							resourceCategorsResPo.setResCategoryName( resourceCategors.getResName() );
							resourceCategorsResPo.setResTable( resTable );

							if (!resourceCategorsResPoList.contains( resourceCategorsResPo )) {
								resourceCategorsResPoList.add( resourceCategorsResPo );
							}
							ResourceCategorsResListMongo.addResourceCategorsResList( resourceCategorsResPoList,
									InstitutionLoadUtils.getString( "institutionId" ) );
						}
					}

					for (ResCategoryRelations resCategoryRelations : resultResCategoryRelationsList) {
						// 登记资源分类资源变更表
						// 记录接触关系的资源
						ResourceUpdateRecord resourceUpdateRecord = new ResourceUpdateRecord();
						resourceUpdateRecord.setResourceUpdateRecordId( StringUtil.createSystemDataPrimaryKey() );
						resourceUpdateRecord.setResId( resCategoryRelations.getResId() );
						ResourceType resType = resourceTypeMapper.selectResourceTypeResTableExits( resTable );
						resourceUpdateRecord.setResTable( resType.getResTable() );
						resourceUpdateRecord.setResTypeId( resType.getResTypeId() );
						ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
						resourceUpdateRecord.setSuperCategoryId( resourceCategors.getParentId() );
						resourceUpdateRecord.setResourceCategoryId( resCategoryRelations.getResCategoryId() );
						resourceUpdateRecord.setOperatedate( DateUtil.getCurDate_YYYY_MM_DD() );
						resourceUpdateRecord.setState( "1" );
						iResourceUpdateRecordService.insert( resourceUpdateRecord );
					}
				}
			}
			AuditLogs auditLogs = null;
			List<AuditLogs> auditLogsList = auditLogsMapper.getAuditLogsListByResId( videosReqVo.getResources().getResId() );
			if (null != auditLogsList && auditLogsList.size() > 0) {
				auditLogs = auditLogsList.get( 0 );
			}
			videosResourceMongoVo.setAuditLogs( auditLogs );

			DhResourceauditlogs dhResourceAuditLogs = dhResourceauditlogsMapper.getResAuditlogsByResId( videosReqVo.getResources().getResId() );
			videosResourceMongoVo.setResourceauditlogs( dhResourceAuditLogs );

			DhTodayStorageInfos dhTodayStorageInfos = null;
			List<DhTodayStorageInfos> todayStorageInfosList = todayStorageInfosDao.getDhTodayStorageInfosByResId( videosReqVo.getResources()
					.getResId() );
			if (null != todayStorageInfosList && todayStorageInfosList.size() > 0) {
				dhTodayStorageInfos = todayStorageInfosList.get( 0 );
			}
			videosResourceMongoVo.setTodayStorageInfos( dhTodayStorageInfos );

			List<ResourceRelations> resourceRelations = this.resourceRelationsMapper.getResourceRelationsListByResId( resources.getResId() );
			videosResourceMongoVo.setDhResourceRelationsList( resourceRelations );

			VideosMongo.updateVideosByVideosReqVo( videosResourceMongoVo, InstitutionLoadUtils.getString( "institutionId" ) );
		}
		return result;
	}

	@Override
	public int deleteVideosByIdBatch(List<String> resIdList) throws Exception {
		int result = 0;
		if (null != resIdList && resIdList.size() > 0) {
			for (String resId : resIdList) {
				Videos queryVideos = selectByPrimaryKey( resId );
				if (null != queryVideos) {
					// 1、删除
					result += deleteByPrimaryKey( queryVideos.getResId() );
					// 第二步删除资源分类关系
					List<ResCategoryRelations> resCategoryRelationList = resCategoryRelationsMapper.getResCategoryRelationsListByResId( queryVideos
							.getResId() );
					for (ResCategoryRelations resCategoryRelations : resCategoryRelationList) {
						resourceRelationsMapper.deleteByPrimaryKey( resCategoryRelations.getResCategoryRelationId() );
						// 登记资源分类资源变更表
						// 记录接触关系的资源
						ResourceUpdateRecord resourceUpdateRecord = new ResourceUpdateRecord();
						resourceUpdateRecord.setResourceUpdateRecordId( StringUtil.createSystemDataPrimaryKey() );
						resourceUpdateRecord.setResId( resCategoryRelations.getResId() );
						ResourceType resType = resourceTypeMapper.selectResourceTypeResTableExits( "Videos" );
						resourceUpdateRecord.setResTable( resType.getResTable() );
						resourceUpdateRecord.setResTypeId( resType.getResTypeId() );
						ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
						resourceUpdateRecord.setSuperCategoryId( resourceCategors.getParentId() );
						resourceUpdateRecord.setResourceCategoryId( resCategoryRelations.getResCategoryId() );
						resourceUpdateRecord.setOperatedate( DateUtil.getCurDate_YYYY_MM_DD() );
						resourceUpdateRecord.setState( "0" );
						iResourceUpdateRecordService.insert( resourceUpdateRecord );
					}

					// 第三步删除资源关系
					// 资源关系列表
					List<ResourceRelations> queryResRelationsList = resourceRelationsMapper.getResourceRelationsListByResId( queryVideos.getResId() );
					for (ResourceRelations resRelations : queryResRelationsList) {
						resourceRelationsMapper.deleteByPrimaryKey( resRelations.getResRelationId() );
					}

					// 第四步：删除资源终端关系
					List<SpecialResourceDatas> tempSpecialResDataList = specialResourceDatasMapper.getSpecialResourceDataListByResId( queryVideos
							.getResId() );
					for (SpecialResourceDatas resSpecialDatas : tempSpecialResDataList) {
						specialResourceDatasMapper.deleteBySpecialResourceDataId( resSpecialDatas.getSpecialResDataId() );
					}

					// 5、删除审核日志表关系
					List<AuditLogs> auditLogsList = auditLogsMapper.getAuditLogsListByResId( queryVideos.getResId() );
					for (AuditLogs auditLogs : auditLogsList) {
						auditLogsMapper.deleteByPrimaryKey( auditLogs.getProductLogId() );
					}

					// 清理入库审核日志表关系
					DhResourceauditlogs dhResourceAuditLogs = dhResourceauditlogsMapper.getResAuditlogsByResId( queryVideos.getResId() );
					if (null != dhResourceAuditLogs) {
						dhResourceauditlogsMapper.deleteByPrimaryKey( dhResourceAuditLogs.getId() );
					}

					// 删除流水
					List<DhTodayStorageInfos> dhTodayStorageInfosList = todayStorageInfosDao.getDhTodayStorageInfosByResId( queryVideos.getResId() );
					for (DhTodayStorageInfos dhTodayStorageInfos : dhTodayStorageInfosList) {
						todayStorageInfosDao.deleteTodayStorageInfoById( dhTodayStorageInfos.getStorageId() );
					}

					resourcesMapper.deleteByPrimaryKey( queryVideos.getResId() );
				}
			}
			VideosMongo.deleteVideosByIds( resIdList, InstitutionLoadUtils.getString( "institutionId" ) );

			// 先清理资源所有分类关系
			ResourceCategorsResListMongo.deleteResCategoryRelationsByResId( resIdList, InstitutionLoadUtils.getString( "institutionId" ) );
		}

		return result;
	}
}